<ui:composition template="/dynamic/layout/layout.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

	<ui:define name="content">
		<script>
			jQuery(document).ready(function($) {
				jQuery(".rerenderButton").click();
			});
		</script>
		<div id="welcome">
			<p style="clear: both" />
		</div>
		<h3>Uczelnia</h3>
		<h:form id="showSchoolForm">
			<p:commandButton reRender="showSchoolForm" ajax="true"
				styleClass="rerenderButton" style="display:none" />

			<p:galleria value="#{schoolMBean.actualSchool.photos}" var="photo"
				rendered="#{not empty schoolMBean.actualSchool.photos }">
				<p:graphicImage value="#{schoolMBean.image}" >
					<f:param name="imageIdD" value="#{photo.idPhoto}" />
				</p:graphicImage>
			</p:galleria>

			<table class="showTable">
				<tr>
					<td><label><b>Nazwa:</b> </label></td>
					<td><p>
							<h:outputText value="#{schoolMBean.actualSchool.name}"
								styleClass="login_input_long" />
						</p></td>
				</tr>
				<tr>
					<td><label><b>Data założenia:</b> </label></td>
					<td><p>
							<h:outputText value="#{schoolMBean.actualSchool.foundationYear}"
								styleClass="login_input_long">
								<f:convertDateTime pattern="dd/MM/yyyy" />
							</h:outputText>
						</p></td>
				</tr>
				<tr>
					<td><label style="height: 100px"><b>Opis:</b> </label></td>
					<td><p>
							<h:outputText id="description" styleClass="login_input_long"
								label="Opis" value="#{schoolMBean.actualSchool.description}"
								autoResize="false" editable="false">

							</h:outputText>
						</p></td>
				</tr>

			</table>
			<br />
			<br />
			<label>Wydziały:</label>
			<h:form id="formDepartments">
				<p:dataTable id="dataTable" var="department"
					rendered="#{not empty schoolMBean.actualSchool.departments}"
					value="#{schoolMBean.actualSchool.departments}" rows="12"
					paginator="true"
					paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
					rowsPerPageTemplate="9,12,15" paginatorPosition="bottom"
					widgetVar="departmentTable"
					filteredValue="#{departmentMBean.filteredDepartments}"
					emptyMessage="Nie znaleziono żadnych wydziałów.">
					<f:facet name="header">
						<p:outputPanel style="float:right">
							<h:outputText value="Szukaj w wydziałach:" />
							<p:inputText id="globalFilter" onkeyup="departmentTable.filter()"
								style="width:150px" />
						</p:outputPanel>
					</f:facet>

					<p:column sortBy="name" headerText="Nazwa wydziału" filterBy="name"
						filterMatchMode="contains">
						<h:outputText value="#{department.name}" />
					</p:column>
					<p:column sortBy="school.name" headerText="Uczelnia"
						filterBy="school.name" filterMatchMode="contains">
						<h:outputText value="#{department.school.name}" />
					</p:column>

					<p:column headerText="Akcje">
						<div class="action-div">
							<p:commandLink title="Pokaż"
								action="#{departmentMBean.showDepartment}" ajax="false">
								<img
									src="${facesContext.externalContext.requestContextPath}/static/images/pokaz.PNG"
									alt="Pokaz" />
								<f:param value="#{department.idDepartment}" name="departmentId" />
							</p:commandLink>
							<p:commandLink title="Edytuj"
								action="#{departmentMBean.editDepartment}" ajax="false"
								rendered="#{request.isUserInRole('ROLE_ADMIN')}">
								<img
									src="${facesContext.externalContext.requestContextPath}/static/images/edytuj.PNG"
									alt="Edytuj" />
								<f:param value="#{department.idDepartment}" name="departmentId" />
							</p:commandLink>
							<p:commandLink title="Usuń"
								action="#{departmentMBean.removeDepartment}" ajax="false"
								rendered="#{request.isUserInRole('ROLE_ADMIN')}">
								<img
									src="${facesContext.externalContext.requestContextPath}/static/images/kosz.PNG"
									alt="Usuń" />
								<f:param value="#{department.idDepartment}" name="departmentId" />
							</p:commandLink>
						</div>
					</p:column>
				</p:dataTable>
				<p:commandButton id="addnewdepartment"
					action="#{departmentMBean.addDepartment}" value="Dodaj wydział"
					ajax="false">
					<f:setPropertyActionListener
						value="#{schoolMBean.actualSchool.idSchool}"
						target="#{departmentMBean.choosenId}" />
				</p:commandButton>
			</h:form>


		</h:form>
		<div id="main_content"></div>

	</ui:define>
</ui:composition>